/*
 * sevenseg.h
 *
 *  Created on: 18-10-2012
 *      Author: Skeith
 */

/*
 * Zarzdzadzanie wyswietlaczem siedmio segmentowym
 * 0 - stan niski, podswietla odpowiedni segment
 * 1 - stan wysoki, gasi segment
 */

#ifndef SEVENSEG_H_
#define SEVENSEG_H_

#include "../Startup/general.h"
#include "../Startup/lpc2xxx.h"

#define SEVEN_SEG_A   0x00010000
#define SEVEN_SEG_B   0x00020000
#define SEVEN_SEG_C   0x00040000
#define SEVEN_SEG_D   0x04000000
#define SEVEN_SEG_E   0x08000000
#define SEVEN_SEG_F   0x10000000
#define SEVEN_SEG_G   0x20000000
#define SEVEN_SEG_DOT 0x40000000

#define SEG_0 (SEVEN_SEG_A | SEVEN_SEG_B | SEVEN_SEG_C | SEVEN_SEG_D | SEVEN_SEG_E | SEVEN_SEG_F )
#define SEG_1 (SEVEN_SEG_B | SEVEN_SEG_C)
#define SEG_2 (SEVEN_SEG_A | SEVEN_SEG_B | SEVEN_SEG_D | SEVEN_SEG_E| SEVEN_SEG_G)
#define SEG_3 (SEVEN_SEG_A | SEVEN_SEG_B | SEVEN_SEG_C | SEVEN_SEG_D                             | SEVEN_SEG_G)
#define SEG_4 (              SEVEN_SEG_B | SEVEN_SEG_C                             | SEVEN_SEG_F | SEVEN_SEG_G)
#define SEG_5 (SEVEN_SEG_A               | SEVEN_SEG_C | SEVEN_SEG_D               | SEVEN_SEG_F | SEVEN_SEG_G)
#define SEG_6 (SEVEN_SEG_A               | SEVEN_SEG_C | SEVEN_SEG_D | SEVEN_SEG_E | SEVEN_SEG_F | SEVEN_SEG_G)
#define SEG_7 (SEVEN_SEG_A | SEVEN_SEG_B | SEVEN_SEG_C                                                        )
#define SEG_8 (SEVEN_SEG_A | SEVEN_SEG_B | SEVEN_SEG_C | SEVEN_SEG_D | SEVEN_SEG_E | SEVEN_SEG_F | SEVEN_SEG_G)
#define SEG_9 (SEVEN_SEG_A | SEVEN_SEG_B | SEVEN_SEG_C | SEVEN_SEG_D               | SEVEN_SEG_F | SEVEN_SEG_G)

#define SEG_UP (SEVEN_SEG_A)
#define SEG_DOWN (SEVEN_SEG_D)
#define SEG_LEFT (SEVEN_SEG_E | SEVEN_SEG_F)
#define SEG_RIGHT (SEVEN_SEG_B | SEVEN_SEG_C)

#define SEVEN_SEG_PINS (1 << 16 | 1 << 17 | 1 << 18 | 1 << 26 | 1 << 27 | 1 << 28 | 1 << 29 | 1 << 30)

//IODID register
#define SEVEN_SEG_IODIR (SEVEN_SEG_PINS)

//PINSEL0
#define SEVEN_SEG_PINSEL0 ()
//PINSEL1
#define SEVEN_SEG_PINSEL1 (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 5 | 1 << 20 | 1 << 21 | 1 << 22 | 1 << 23 | 1 << 24 | 1 << 25 | 1 << 26 | 1 << 27 | 1 << 28 | 1 << 29)

enum SegDirection
{
	UP = 1,
	DOWN = 2,
	LEFT = 4,
	RIGHT = 8
};

void SegInit(void);
void SegClrAll(void);
void SegClr (tU32 val);
void SegSet(tU32 val);
void SegSetNumber(tU8 num);
void SegSetDirection(enum SegDirection dir);
void SegTest(void);



#endif /* SEVENSEG_H_ */
